#include "OriginPCH.h"
#include "WindowsInput.h"
#include "Core/Application.h"
#include <GLFW/glfw3.h>

namespace Origin
{
#define GET_GLFW_WINDOW static_cast<GLFWwindow*>(Application::Get().GetWindow().GetNativeWindow());
    
    Input* Input::_instance = new WindowsInput();

    bool WindowsInput::IsKeyPressedImplement(int keyCode)
    {
        auto window = GET_GLFW_WINDOW;
        auto state = glfwGetKey(window, keyCode);
        return state == GLFW_PRESS || state == GLFW_REPEAT;
    }

    bool WindowsInput::IsMouseButtonPressedImplement(int button)
    {
        auto window = GET_GLFW_WINDOW;
        auto state = glfwGetMouseButton(window, button);
        return state == GLFW_PRESS;
    }

    std::pair<float, float> WindowsInput::GetMousePositionImplement()
    {
        auto window = GET_GLFW_WINDOW;
        double x, y;
        glfwGetCursorPos(window, &x, &y);
        return std::pair{x, y};
    }

    float WindowsInput::GetMouseXImplement()
    {
        return GetMousePositionImplement().first;
    }

    float WindowsInput::GetMouseYImplement()
    {
        return GetMousePositionImplement().second;
    }
}